#include "LineRenderer.h"
#include <math.h>

void LineRenderer::scan(unsigned char* p,int len,Interpolant base,Interpolant& diff)
{

}

void LineRenderer::drawLine(float x1,float y1,float x2,float y2)
{
	float len=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	float vx=(x2-x1)/len,vy=(y2-y1)/len;
	float x=x1,y=y1;
	for (int i=0;i<(int) len;i++)
	{
		if (x >= 0 && y >= 0 && x <= this->m_width && y <= this->m_height)
                        m_data[((int) y)*this->m_stride+((int) x)*3+1]=255;
		x+=vx;
		y+=vy;
	}
}

void LineRenderer::render(RendererVertex v[3])
{
	drawLine(v[0].pos.x,v[0].pos.y,v[1].pos.x,v[1].pos.y);
	drawLine(v[1].pos.x,v[1].pos.y,v[2].pos.x,v[2].pos.y);
	drawLine(v[2].pos.x,v[2].pos.y,v[0].pos.x,v[0].pos.y);

	/*
	unsigned char* buffer=target->bits();
	int w=target->width(),h=target->height();
	int stride=target->bytesPerLine();
	unsigned char* data=target->bits();
	int x,y;
	for (y=0;y<50;y++)
	{
		for (x=0;x<250;x+=3)
		{
		   data[x]=255;
		}
		data+=stride;
	}
	*/
}
